#ifndef WEATHERWIDGET_H
#define WEATHERWIDGET_H

#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QTimer>
#include <QHeaderView>
#include <QStringListModel>
#include <QCompleter>
#include <QComboBox>
#include <QLabel>
#include <QProgressBar>
#include <QFile>
#include <QTextStream>
#include <QTableWidget>
#include <QMap>
#include <QKeyEvent>

namespace Ui {
class WeatherWidget;
}
class WeatherWidget : public QWidget {
    Q_OBJECT

public:
    WeatherWidget(QWidget *parent = nullptr);
    ~WeatherWidget();

private slots:
    void fetchCityList();
    void parseCityList(const QJsonArray &districts, QStringList &cities);
    void on_button_clicked(const QString &city);
    void on_network_reply(QNetworkReply *reply);
    void on_network_timeout();

protected:
    bool eventFilter(QObject *watched, QEvent *event) override;

private:
    void update_table(const QJsonObject &live);
    QString fieldToChinese(const QString &field) const;

    QComboBox *cityComboBox;
    QTableWidget *tableWidget;
    QStringListModel *cityListModel;
    QNetworkAccessManager *networkManager;
    QTimer *timeoutTimer;
};

#endif // WEATHERWIDGET_H
